// 请求通用方法
import apiMixin from '@/mixin/apiMixin';
// 任务通用方法
import taskMixin from '@/mixin/taskMixin';

import utils from '@/utils/index';
export default {
    mixins: [apiMixin,taskMixin],
    data() {
        return {
            tableData:[],
            listNumsTotal: 0,
            loading: false,
            searchText: '',
            curIndex: 0,
            curPage: 1,
        }
    },
    mounted() {
        this.init();
    },
    methods: {
        init() {
            this.getProjectListBySubIdApi(this.curPage);
        },
        getProjectListBySubIdApi(page) {
            let subjectId = this.$route.query.id;
            let _self = this;
            this.comResquest(this.request.getProjectListBySubId,(res)=>{
                _self.curPage = Number(page) || 1;
                _self.updateRoutePar(page);
                let { count,result } = res;
                _self.listNumsTotal = count;
                _self.tableData = result;
            },{
                load: true,
                platform_id: subjectId,
                page,
                keyword: this.searchText
            });
        },
        postEditProjectApi() {
            let _self = this;
            let changeObj = utils.simpleCopy(this.tableData[this.curIndex])
            this.comResquest(this.request.postEditProject,(res)=>{
                _self.init();
                _self.$message({
                    message: '操作成功',
                    type: 'success'
                });
            },{
                load: true,
                id: changeObj.id,
                status: changeObj.status
            });
        },
        deleteProjectApi() {
            let _self = this;
            let changeObj = utils.simpleCopy(this.tableData[this.curIndex])
            this.comResquest(this.request.deleteProject,(res)=>{
                _self.init();
                _self.$message({
                    message: '删除成功',
                    type: 'success'
                });
            },{
                load: true,
                id: changeObj.id,
            });
        },
        searchWill() {
            this.getProjectListBySubIdApi();
        },
        handleStatusChange(changeIndex) {
            this.curIndex = changeIndex;
            this.postEditProjectApi();
        },
        deleteSubject(delIndex) {
            this.curIndex = delIndex;
            this.deleteProjectApi();
        },
        navAddProject() {
            let subjectId = this.$route.query.id;
            this.$router.push('/task/projectDetail?subjectId='+subjectId);
        },
        changePage(page){
            page = page || 1;
            this.getProjectListBySubIdApi(page);
        },
    },
}